require('./index.css');
let _util = require('util/util.js');
let htmlTemplate = require('./index.art');



let CommonModal = function () {
    let _this = this;

    //顶部关闭弹窗
    $(document).on('click', '.close-btn', function (e) {
        e.stopPropagation();
        $(this).parents('.image-modal-wrapper').hide();
    });

    //底部关闭弹窗
    $(document).on('click', '.jsCloseModal', function (e) {
        $('.close-btn').trigger('click');
    });

    //文件上传
    $('#fileUpload-edit').fileupload({
        dataType: 'json',
        done: function (e, data) {
            $.each(data.result.files, function (index, file) {
                $('<p/>').text(file.name).appendTo(document.body);
            });
        }
    });

};

CommonModal.prototype.render = function (option) {
    if (!(option.container instanceof window.jQuery)) {
        return
    }

    let renderedHtml = _util.renderHtml(__dirname + htmlTemplate, option || {});
    option.container.html(renderedHtml);

    //目录编辑状态下才执行，新增不执行
    if (option.data) {
        let data = option.data;
        $('#boxNo').val(data['boxNo']);
        $('#fileNo').val(data['fileNo']);
        $('#names').val(data['names'].toString());
        $('#positionNo').val(data['positionNo']);
    }
}

module.exports = CommonModal;